layui.use(['table', 'jquery', 'form', 'admin'], function () {
    let form = layui.form,
        $ = layui.jquery;

    $.ajax({
        type: "GET",
        url: '/api/article/top',
        dataType: 'json',
        data: {},
        success: function (data) {
            if (data.status === 200) {
                if (data.data.top.length < 2) {
                    return ;
                }
                let converter = new showdown.Converter();
                let html_content = ""
                // top
                $('#top1').html(data.data.top[0].title)
                $('#top1').attr('href', '/article?id=' + data.data.top[0].id)
                $('#top-date1').html(data.data.top[0].date)
                $('#top-author1').html(data.data.top[0].author)
                $('#top-view1 span').eq(1).html(data.data.top[0].view)
                $('#top-image1').attr('src', data.data.top[0].photo)
                html_content = converter.makeHtml(data.data.top[0].content);
                $('#top-content1').html(html_content)


                $('#top2').html(data.data.top[1].title)
                $('#top2').attr('href', '/article?id=' + data.data.top[1].id)
                $('#top-date2').html(data.data.top[1].date)
                $('#top-author2').html(data.data.top[1].author)
                $('#top-view2 span').eq(1).html(data.data.top[1].view)
                $('#top-image2').attr('src', data.data.top[1].photo)
                html_content = converter.makeHtml(data.data.top[1].content);
                $('#top-content2').html(html_content)

                //newest
                $('#new1').html(data.data.newest[0].title)
                $('#new1').attr('href', '/article?id=' + data.data.newest[0].id)
                $('#new-date1').html(data.data.newest[0].date)
                $('#new-author1').html(data.data.newest[0].author)
                $('#new-view1 span').eq(1).html(data.data.newest[0].view)
                $('#new-image1').attr('src', data.data.newest[0].photo)
                html_content = converter.makeHtml(data.data.newest[0].content);
                $('#new-content1').html(html_content)

                $('#new2').html(data.data.newest[1].title)
                $('#new2').attr('href', '/article?id=' + data.data.newest[1].id)
                $('#new-date2').html(data.data.newest[1].date)
                $('#new-author2').html(data.data.newest[1].author)
                $('#new-view2 span').eq(1).html(data.data.newest[1].view)
                $('#new-image2').attr('src', data.data.newest[1].photo)
                html_content = converter.makeHtml(data.data.newest[1].content);
                $('#new-content2').html(html_content)
            } else {
                layui.use('layer', function () {
                    layer.msg(data.msg)
                });
            }
        },
        err: function () {
            layui.use('layer', function () {
                layer.msg("服务器请求失败")
            });
        }
    });
});